﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_Galleries_ctrGalleryDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }
    }

    private void DataBind()
    {
        int nCurrentLang = Support.GetCurrentLanguage();
        int nPageCount = 0;
        int nItem = ConvertData.ConvertToInt(Request.QueryString[Config.ALBUM_ID]);
        try
        {
            Albums objAlbum = new Albums();
            objAlbum.LoadById(nItem);
            switch (nCurrentLang)
            {
                case 1:
                    lblTitle.Text ="Album: " + " " +  objAlbum.Data.AlbumName1;
                    break;
                case 2:
                    lblTitle.Text = "Album: " + " " + objAlbum.Data.AlbumName2;
                    break;
                case 3:
                    lblTitle.Text = "Album: " + " " +  objAlbum.Data.AlbumName3;
                    break;
            }
            AlbumImages obj = new AlbumImages();
            DataTable dtb = new DataTable();
            dtb = obj.Search(nItem, 1, 1000, ref nPageCount);
            dtlGallery.DataSource = dtb;
            dtlGallery.DataBind();
        }
        catch
        {
            Response.Redirect("~/Default.aspx");
        }
    }
    protected void dtlGallery_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            System.Web.UI.HtmlControls.HtmlImage imgGallery = (System.Web.UI.HtmlControls.HtmlImage)e.Item.FindControl("imgGallery");
            System.Web.UI.HtmlControls.HtmlAnchor lnkGallery = (System.Web.UI.HtmlControls.HtmlAnchor)e.Item.FindControl("lnkGallery");
            
            string sFileName = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ImageName"));
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "AlbumID"));

            imgGallery.Src = Config.ROOT + Config.IMAGE_GALLERY_DEFAULT_UPLOAD  + sFileName;
            lnkGallery.HRef = Config.ROOT + Config.IMAGE_GALLERY_DEFAULT_UPLOAD + sFileName;
        }
    }
}
